package com.cx.mall.user.service.impl;


import com.cx.mall.user.dao.IBaseDao;
import com.cx.mall.user.service.IBaseService;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public abstract class BaseServiceImpl<M extends IBaseDao<T>,T> implements IBaseService<T> {
    private M baseDao; // 具体的子 DAO
    /**
     * 注入 dao，使用 setter 方法赋值
     * @param baseDao
     */
    public void setBaseDao(M baseDao) {
        this.baseDao = baseDao;
    }
    @Override
    public void save(T entity) throws Exception {
        baseDao.insert(entity);
    }
    @Override
    public void update(T entity) throws Exception {
        baseDao.update(entity);
    }
    @Override
    public void removeById(Object id) throws Exception {
        baseDao.deleteById(id);
    }
    @Override
    public T getById(Object id) throws Exception {
        return baseDao.selectById(id);
    }
    @Override
    public T getOne(Object... params) throws Exception {
        return baseDao.selectOne(params);
    }
    @Override
    public List<T> list(Object... params) throws Exception {
        return baseDao.selectList(params);
    }
}
